<?php
/*d*/
class PluginContentwedding_ModuleSitemap extends PluginContentwedding_Inherit_PluginSitemap_ModuleSitemap {

    /**
     * Change data for Sitemap Index
     *
     * @return array
     */
    public function getExternalCounters() {
        $aCounters = parent::getExternalCounters();
        $aCounters['pages'] = ceil($this->PluginContentwedding_News_GetCountOfActivePages() / Config::Get('plugin.sitemap.objects_per_page'));

        return $aCounters;
    }

    /**
     * Get data for static pages Sitemap
     *
     * @param integer $iCurrPage
     * @return array
     */
    public function getDataForPages($iCurrPage) {
        $iPerPage = Config::Get('plugin.sitemap.objects_per_page');
        $sCacheKey = "sitemap_pages_{$iCurrPage}_" . $iPerPage;

        if (false === ($aData = $this->Cache_Get($sCacheKey))) {
            $iCount = 0;
            $aPages = $this->PluginContentwedding_News_GetListOfActivePages($iCount, $iCurrPage, $iPerPage);

            $aData = array();
            foreach ($aPages as $oPage) {
                $aData[] = $this->PluginSitemap_Sitemap_GetDataForSitemapRow(
                    Router::GetPath('news') . $oPage->getUrlFull(),
                    $oPage->getDateEdit(),
                    Config::Get('plugin.contentwedding.sitemap.sitemap_priority'),
                    Config::Get('plugin.contentwedding.sitemap.sitemap_changefreq')
                );
            }

            $this->Cache_Set($aData, $sCacheKey, array('news_change'), Config::Get('plugin.contentwedding.sitemap.cache_lifetime'));
        }

        return $aData;
    }
}
